//
//  BFListViewController.m
//  beifang
//
//  Created by Apple on 17/4/18.
//  Copyright © 2017年 郭凯. All rights reserved.
//

#import "BFListViewController.h"

@interface BFListViewController ()<UITableViewDataSource>
@property (strong, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation BFListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    self.tableView.dataSource = self;
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadFirstPage)];
    //    header.arrowView.image = [UIImage imageNamed:@"arrow_head"];
    header.stateLabel.hidden = YES;
    header.lastUpdatedTimeLabel.hidden = YES;
    header.automaticallyChangeAlpha = YES;
    self.tableView.mj_header = header;
    
    extern NSInteger tesetNum ;
    NSLog(@"tesetNum=%ld",tesetNum);
    tesetNum = 99;
    NSLog(@"tesetNum=%ld",tesetNum);
    
        
 
    MJRefreshAutoNormalFooter *footer= [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMorePage)];
    self.tableView.mj_footer = footer;
    [footer setTitle:@"加载完毕" forState:MJRefreshStateNoMoreData];
    [footer setTitle:@"上拉加载" forState:MJRefreshStateIdle];
    [footer setTitle:@"正在加载..." forState:MJRefreshStateRefreshing];
//    [self.tableView.mj_header beginRefreshing];

}


// 加载第一页数据
-(void)loadFirstPage{
    NSLog(@"加载第一页数据");
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.tableView.mj_header endRefreshing];
        num = 10;
        [self.tableView reloadData];
    });
}
//加载更多页面
int num = 10;
-(void)loadMorePage{
    NSLog(@"加载更多页数据");
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.tableView.mj_footer endRefreshing];
        num += 10;
        [self.tableView reloadData];
    });

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return num;
    
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.textLabel.text = @"测试";
    return cell;
}
@end
